package at.socialconference.backend.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "t_places")
public class Place implements Insertable {

	public Place() {}

	public Place(at.socialconference.inter.model.Place place) {
		this.description = place.getDescription();
		this.id = place.getId();
		this.latitude = place.getLatitude();
		this.longitude = place.getLongitude();
		this.name = place.getName();
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "placeid")
	private Integer id;

	@Column(name = "name")
	private String name;

	@Column(name = "description")
	private String description;

	@Column(name = "longitude")
	private Double longitude;

	@Column(name = "latitude")
	private Double latitude;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public at.socialconference.inter.model.Place generateInterPlace() {
		return new at.socialconference.inter.model.Place(id, name, description, longitude, latitude);
	}

	public static List<at.socialconference.inter.model.Place> getInterPlaces(
			List<Place> backendPlaces) {
		ArrayList<at.socialconference.inter.model.Place> result = new ArrayList<at.socialconference.inter.model.Place>();
		for (int i = 0; i < backendPlaces.size(); i++) {
			at.socialconference.inter.model.Place temp = backendPlaces.get(i).generateInterPlace();
			result.add(i, temp);
		}

		return result;
	}
}
